package com.dinzeer.sjapadder.se;

import com.dinzeer.legendreliclib.lib.util.FastMakeEntityUtil;
import com.dinzeer.sjapadder.register.SjaSpecialEffectRegsitry;
import com.dinzeer.sjapadder.register.SjaStacksReg;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import mods.flammpfeil.slashblade.event.SlashBladeEvent;
import mods.flammpfeil.slashblade.registry.specialeffects.SpecialEffect;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class TheBlueDreams extends SpecialEffect {
    public TheBlueDreams() {
        super(30);
    }
    @SubscribeEvent
    public static void onSlashBladeHit(SlashBladeEvent.HitEvent event) {
        ISlashBladeState state=event.getSlashBladeState();
        if (state.hasSpecialEffect(SjaSpecialEffectRegsitry.TheBlueDreams.getId())){
            if (!(event.getUser() instanceof Player player))return;
            if (SpecialEffect.isEffective(SjaSpecialEffectRegsitry.TheBlueDreams.get(), player.experienceLevel)) {
                SjaStacksReg.BlueDreamCombo.addStacks( player, 1);
                if (SjaStacksReg.BlueDreamCombo.getCurrentStacks(player)>=SjaStacksReg.BlueDreamCombo.getMaxStacks()){
                    SjaStacksReg.BlueDreamCharger.addStacks(player, 1);
                    SjaStacksReg.BlueDreamCombo.addStacks( player,-SjaStacksReg.BlueDreamCombo.getMaxStacks());
                    if (SjaStacksReg.BlueDreamCharger.getCurrentStacks(player)>=SjaStacksReg.BlueDreamCharger.getMaxStacks()
                    && SjaStacksReg.BlueDreamChargerSuper.getCurrentStacks(player)<SjaStacksReg.BlueDreamChargerSuper.getMaxStacks()
                    ){
                        SjaStacksReg.BlueDreamChargerSuper.addStacks(player, 1);
                        SjaStacksReg.BlueDreamCharger.addStacks(player,-SjaStacksReg.BlueDreamCharger.getMaxStacks());
                    }
                }
                float MagicDamage = (float) ((state.getBaseAttackModifier()
                                        *(SjaStacksReg.BlueDreamCharger.getCurrentStacks(player)*0.5f)));
                event.getTarget().hurt(FastMakeEntityUtil.DamageSourceToCreat(player, DamageTypes.MAGIC),MagicDamage);
                event.getTarget().invulnerableTime = 0;
                float soundDamage= (float) ((state.getBaseAttackModifier()))*(SjaStacksReg.BlueDreamChargerSuper.getCurrentStacks(player)*1.0f);
                event.getTarget().hurt(FastMakeEntityUtil.DamageSourceToCreat(player, DamageTypes.SONIC_BOOM),soundDamage);
            }
        }
    }















}
